#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll t;
ll d[100010],v[100010],a[100010];
ll ps[1000010],p[1000010];
ll ans1=0,ans2;
ll cs(ll x,ll y){
    if(x%y==0) return x/y;
    else return x/y+1;
}
struct xd{
    int l,r,len;
};
ll tmm[800080],tag[800080];
ll tm2[800080];
bool tp[800080];
bool vis[100010];
ll dy[100010];
void push_down(ll p,ll l,ll r){
    ll mid = (l+r) >> 1;
    tag[p<<1]+=tag[p];
    tag[p<<1|1]+=tag[p];
    tmm[p<<1]+=(mid-l+1)*tag[p];
    tmm[p<<1|1]+=(r-mid)*tag[p];
    tag[p]=0;
    return ;
}
void build(ll p,ll l,ll r){
    if(l==r){
        tmm[p] = 0;
        tag[p] =0;
        tp[p]=0;
        tm2[p] = l;
        dy[l] = p;
    }
    else{
        ll mid = (l+r) >> 1;
        build(p<<1,l,mid);
        build(p<<1|1,mid+1,r);
        tp[p] =tmm[p]= 0;
        tm2[p] = tm2[p<<1];
    }
    return;
}
void bg(ll p,ll l,ll r,ll x){
    if(l==x&&r==l){
        tp[p]  =1;
    }
    else{
        ll mid = (l+r) >> 1;
        if(x<=mid) bg(p<<1,l,mid,x);
        else bg(p<<1|1,mid+1,r,x);
        if((tp[p<<1]==true||tp[p<<1|1]==true)) tp[p] = 1;
        else tp[p]=0;
    }
    return;
}
bool fbg(ll p,ll l,int r,int x,int y){
    if(l==x&&r==y){
        return tp[p];
    }
    else{
        ll mid  = (l+r) >> 1;
        if(y<=mid) return fbg(p<<1,l,mid,x,y);
        else if(x>=mid+1) return fbg(p<<1|1,mid+1,r,x,y);
        else {
            if(fbg(p<<1,l,mid,x,mid)==true) return true;
            if(fbg(p<<1|1,mid+1,r,mid+1,y)==true) return true;
            else return false;
        }
    }
}
void change(ll p,ll l,ll r,ll x,ll y,ll v){
    if(l==x&&y==r){
        tmm[p]+=(r-l+1)*v;
        tag[p]+=v;
        push_down(p,l,r);
    }
    else{
        push_down(p,l,r);
        int mid = (l+r) >> 1;
        if(y <= mid){
            change(p<<1,l,mid,x,y,v);
        }
        else if(x>=mid+1){
            change(p<<1|1,mid+1,r,x,y,v);
        }
        else{
            change(p<<1,l,mid,x,mid,v);
            change(p<<1|1,mid+1,r,mid+1,y,v);
        }
        if(tmm[p<<1]>tmm[p<<1|1]){
            tmm[p] = tmm[p<<1];
            tm2[p] = tm2[p<<1];
        }
        else{
            tmm[p] = tmm[p<<1|1];
            tm2[p] = tm2[p<<1|1];
        }
    }
    return;
}
ll fmaxx(ll p,ll l,ll r,ll x,ll y){
    if(l==x&&r==y){
        return tm2[p];
    }
    else{
        int mid  = (l+r) >> 1;
        int ret=0,summ=0;
        if(y<=mid) {
            ret =fmaxx(p<<1,l,mid,x,y);
        }
        else if(x>=mid+1) {
            ret= fmaxx(p<<1|1,mid+1,r,x,y);
        }
        else{
            ret=fmaxx(p<<1,l,mid,x,mid);
            summ = tmm[dy[ret]];
            if(tmm[dy[fmaxx(p<<1|1,mid+1,r,mid+1,y)]]>summ){
                ret = fmaxx(p<<1|1,mid+1,r,mid+1,y);
            }
        } 
        return ret;
    }

}
xd xds[100010];
int top=0;
bool cmp2(xd x,xd y){
    return x.len < y.len;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%lld",&t);
    
    for(ll nt=1;nt<=t;nt++){
        ll n,m,L,V;
        ans1=0;
        ans2=0;
        scanf("%lld%lld%lld%lld",&n,&m,&L,&V);
        L+=1;
        top=0;
        build(1,1,m);
        for(ll i=1;i<=n;i++){
            scanf("%lld%lld%lld",&d[i],&v[i],&a[i]);
            d[i]+=1;
            vis[i]=0;
        }
        for(ll i=0;i<=L;i++){
            ps[i]=0;
        }
        for(ll i=1;i<=m;i++){
            scanf("%lld",&p[i]);
            p[i]+=1;
            ps[p[i]]++;
            
        }
        for(ll i=1;i<=L;i++){
            ps[i]+=ps[i-1];
        }
        
        sort(p+1,p+1+m);
        for(ll i=1;i<=n;i++){
            ll l,r;
            if(a[i]==0){
                if(v[i]<=V){
                    l=L+1,r=L+1;
                }
                else{
                    l = d[i];
                    r=L;
                }
            }
            else if(a[i]>0){
                l = cs(V*V-v[i]*v[i],2*a[i])+d[i];
                r=L;
            }
            else {
                if(v[i]>V){
                    l=d[i];
                    r = min(l+((V*V-v[i]*v[i])/(2*a[i])),L);
                }
                else l=r=L+1;
            }
            
            if(l>r) continue;
            if(ps[r]-ps[l-1]>0){
                ans1++;
                xds[++top].l = lower_bound(p+1,p+1+m,l)-p;
                xds[top].r = lower_bound(p+1,p+1+m,r)-p;
                if(p[xds[top].r]>r) {
                    xds[top].r--;
                }
                if(xds[top].l<1) xds[top].l=1;
                if(xds[top].r>m) xds[top].r=m;
                xds[top].len = xds[top].r - xds[top].l +1;
                
            }
        }
        sort(xds+1,xds+1+top,cmp2);
        for(int i=1;i<=top;i++){
            int l1 = xds[i].l ,r1=xds[i].r;
            bool f=0;
            for(int j=l1;j<=r1;j++){
                if(tmm[dy[j]]==0){
                    f=1;
                }
            }
            if(f==1) {
                vis[i]=0;
                change(1,1,m,l1,r1,1);
            }
            else vis[i]=1;
        }
        
        for(ll i=1;i<=top;i++){
            if(vis[i]==0){
                int l1 = xds[i].l ,r1=xds[i].r;
                //cerr << vis[i] << endl;
                //if(nt==2) cerr << i <<' '<<ls[i] <<' '<<rs[i] << " ddd"<<endl;
                ll mp = fmaxx(1,1,m,l1,r1);
                ans2++;
                for(ll j=1;j<=top;j++){
                    int l2 = xds[j].l ,r2=xds[j].r;
                    if(vis[j]==0&&mp>=l2&&mp<=r2){
                        vis[j]=1;
                        change(1,1,m,l2,r2,-1);
                    }
                }
                
            }
            
            
        }
        printf("%lld %lld\n",ans1,m-ans2);

    }
    return 0;
}